<h1>Laporan Harian</h1>
<hr/>
<div class="floatleft width20p height600">
<form action="<?php echo base_url();?>ajax/harian" method="get" id="laporan">
<label for="date1">Tanggal Awal </label>
<input id="date1" type="date" name="date1" required="required"/>

<label for="date2">Tanggal Akhir </label>
<input id="date2" type="date" name="date2" required="required"/>

<label for="tipe">Tipe Barang </label>
<select id="group" form="laporan" name="tipe">
	<option value="SEMUA" selected="selected">SEMUA</option>
	<?php
	foreach ($query_barang->result() as $row):
	?>
	<option value="<?php echo $row->nama;?>" label="<?php echo $row->nama;?>"><?php echo $row->nama;?></option>
	<?php
	endforeach;
	?>
</select>
<input type="checkbox" id="filter" name="filter" />Hanya tampilkan belum obras dan belum setter saja <br/>

<br/>

<input type="button" id="btn_submit" value="Submit"/>
</form>
</div>
<h2 id="title"></h2>

<div class="floatleft border1 padding5" id="table_header">
	
</div>
<hr/>
<br/>

<div class="floatleft height400 width854 scroll" id="content">
</div>

<div id="content_total" class="padding5">
</div>

<div id="show_loading" class="floatleft">
</div>

<script>
</script>

<script type="text/javascript">
<!--
$(document).ready(function(){
	//document.getElementById("date1").valueAsDate  = new Date();
	//document.getElementById("date2").valueAsDate  = new Date();
	$('#btn_submit').click(function() {
			var awal = $('#date1').val();
			var akhir = $('#date2').val();
			var tipe = $('#group').val();
			var filter = $('#filter').is(':checked');
			if(filter) filter = 1;
			else filter = 0;
			
			if(awal=="" || akhir=="") return;
			if(awal>akhir) {
				alert("Tanggal Awal harus lebih kecil dari Tanggal Akhir");
				return;
			}
			generate(awal, akhir, tipe, filter);
			$('#title').html(tipe + " [" + awal + " - " + akhir + "]");
			$('#table_header').html('<span class="width100 inline">Tanggal</span><span class="width100 inline">No Laporan</span><span class="width100 inline">Tipe</span><span class="width100 inline">Rajut</span><span class="width100 inline">Obras</span><span class="width100 inline">Setter</span><span class="width125 inline">Belum Obras</span><span class="width100 inline">Belum Setter</span>');
		});
	});
	function generate(awal, akhir, tipe, filter)
	{
		//$('#content').html('');
		//$('#content_total').html('');
		$('#show_loading').html('<h3>Sedang Proses . . . . . . .</h3>');
		$.ajax({
			type: "POST",
			url: "<?php echo base_url(); ?>ajax/harian/" + awal + "/" + akhir +"/" + tipe +"/" + filter,
			cache:false,
			dataType: "json",
			success: function(msg) {
				var html_builder = "";
				var tot_rajut = 0;
				var tot_obras = 0;
				var tot_setter = 0;
				var tot_belum_obras = 0;
				var tot_belum_setter = 0;
				var str = "";
				var temp = "";
				$.each(msg, function(index, row) {
					var rajut = parseInt(row.rajut);
					var obras = parseInt(row.obras);
					var setter = parseInt(row.setter);
					var belumobras = parseInt(row.belumobras);
					var belumsetter = parseInt(row.belumsetter);
					if(obras > rajut || setter > obras)
					{
						// Error
						temp = '<div class="border1 padding5 bgred">';
					}
					else if(belumobras>0 || belumsetter>0)
					{
						// Warning
						temp = '<div class="border1 padding5 bgyellow">';
					}
					else
					{
						// Normal
						temp = '<div class="border1 padding5 ">';
					}
					str = (
						temp+
						'<span class="width100 inline">'+row.tanggal+'</span>'+
						'<span class="width100 inline">'+'<a target="_blank" href="<?php echo base_url();?>detail/'+row.nolap+'">'+row.nolap+'</a>'+'</span>'+
						'<span class="width100 inline">'+row.nama+'</span>'+
						'<span class="width100 inline">'+row.rajut+'</span>'+
						'<span class="width100 inline">'+row.obras+'</span>'+
						'<span class="width100 inline">'+row.setter+'</span>'+
						'<span class="width125 inline">'+row.belumobras+'</span>'+
						'<span class="width100 inline">'+row.belumsetter+'</span>'+
					'</div>'
					);
					html_builder += str;
					tot_rajut += rajut;
					tot_obras += obras;
					tot_setter += setter;
					tot_belum_obras += belumobras;
					tot_belum_setter += belumsetter;
				});
				$('#content').html(html_builder);
				html_builder = "";
				html_builder += (
					'<div class="floatleft border1 padding5">'+
						'<span class="width300 inline">Total</span>'+
						'<span class="width100 inline">'+tot_rajut+'</span>'+
						'<span class="width100 inline">'+tot_obras+'</span>'+
						'<span class="width100 inline">'+tot_setter+'</span>'+
						'<div class="width125 inline">'+tot_belum_obras+'</div>'+
						'<div class="width100 inline">'+tot_belum_setter+'</div>'+
					'</div>'
				);
				$('#content_total').html(html_builder);
				$('#show_loading').html('');
			}
		});
		return false;
	}
-->
</script>